// run: $exec < input
#include <iostream>
#include <algorithm>
#include <queue>

int const maxn = 100107;
int end_point[maxn * 2], next[maxn * 2], head[maxn];
bool vis[2 * maxn];
int alloc = 2;

int a[2 * maxn][20];
int log_2[maxn * 2];
int depth[maxn], pos[maxn];
int father[maxn];
bool off[maxn];
int n, m, stamp, count;

struct priority_queue
{
	void insert(int x) { heap.push(x); }
	void erase(int x) { del.push(x); }
	int size() { return heap.size() - del.size(); }

	void pop()
	{
		while (del.size() && heap.top() == del.top()) {
			heap.pop();
			del.pop();
		}
		heap.pop();
	}

	int top()
	{
		while (del.size() && heap.top() == del.top()) {
			heap.pop();
			del.pop();
		}
		return heap.top();
	}

	int second_top()
	{
		int tmp = top(); pop();
		int ret = top(); insert(tmp);
		return ret;
	}

	std::priority_queue<int> heap, del;
};

priority_queue s1[maxn], s2[maxn], ans;

void add_edge(int u, int v)
{
	end_point[alloc] = v; next[alloc] = head[u]; head[u] = alloc++;
	end_point[alloc] = u; next[alloc] = head[v]; head[v] = alloc++;
}

void dfs(int u, int from, int dep, priority_queue & s)
{
	s.insert(dep);
	for (int p = head[u]; p; p = next[p]) {
		int v = end_point[p];
		if (vis[p] || v == from) continue;
		dfs(v, u, dep + 1, s);
	}
}

void insert(priority_queue & s)
{
	if (s.size() >= 2) {
		int tmp = s.top() + s.second_top();
		ans.insert(tmp);
	}
}

void erase(priority_queue & s)
{
	if (s.size() >= 2) {
		int tmp = s.top() + s.second_top();
		ans.erase(tmp);
	}
}

int get_size(int u, int from)
{
	int ret = 1;
	for (int p = head[u]; p; p = next[p]) {
		int v = end_point[p];
		if (vis[p] || v == from) continue;
		ret += get_size(v, u);
	}
	return ret;
}

int get_center(int u, int from, int size, int & cg)
{
	int ret = 1;
	bool flag = true;
	for (int p = head[u]; p; p = next[p]) {
		int v = end_point[p];
		if (vis[p] || v == from) continue;
		int tmp = get_center(v, u, size, cg);
		if (2 * tmp > size) flag = false;
		ret += tmp;
	}
	if ((size - ret) * 2 > size) flag = false;
	if (flag) cg = u;
	return ret;
}

int divide_and_cforquer_for_tree(int u)
{
	int cg, size = get_size(u, 0);
	get_center(u, 0, size, cg);
	s2[cg].insert(0);
	for (int p = head[cg]; p; p = next[p])
		if (!vis[p]) {
			int v = end_point[p];
			vis[p] = vis[p ^ 1] = true;
			priority_queue s;
			dfs(v, 0, 1, s);
			int tmp = divide_and_cforquer_for_tree(v);
			father[tmp] = cg;
			s1[tmp] = s;
			s2[cg].insert(s1[tmp].top());
		}
	insert(s2[cg]);
	return cg;
}

void dfs(int u, int from)
{
	a[pos[u] = ++stamp][0] = depth[u] = depth[from] + 1;
	for (int p = head[u]; p; p = next[p]) {
		int v = end_point[p];
		if (v == from) continue;
		dfs(v, u);
		a[++stamp][0] = depth[u];
	}
}

int lca(int u, int v)
{
	u = pos[u]; v = pos[v];
	if (u > v) std::swap(u, v);
	int l = log_2[v - u + 1];
	return std::min(a[u][l], a[v - (1 << l) + 1][l]);
}

int distance(int u, int v)
{
	return depth[u] + depth[v] - 2 * lca(u, v);
}

void turn_off(int x)
{
	erase(s2[x]);
	s2[x].insert(0);
	insert(s2[x]);
	for (int i = x; father[i]; i = father[i]) {
		erase(s2[father[i]]);
		if (s1[i].size()) s2[father[i]].erase(s1[i].top());
		s1[i].insert(distance(father[i], x));
		if (s1[i].size()) s2[father[i]].insert(s1[i].top());
		insert(s2[father[i]]);
	}
}

void turn_on(int x)
{
	erase(s2[x]);
	s2[x].erase(0);
	insert(s2[x]);
	for (int i = x; father[i]; i = father[i]) {
		erase(s2[father[i]]);
		if (s1[i].size()) s2[father[i]].erase(s1[i].top());
		s1[i].erase(distance(father[i], x));
		if (s1[i].size()) s2[father[i]].insert(s1[i].top());
		insert(s2[father[i]]);
	}
}

int main()
{
	std::cin >> n;
	count = n;
	for (int i = 1, x, y; i < n; i++) {
		std::cin >> x >> y;
		add_edge(x, y);
	}

	divide_and_cforquer_for_tree(1);
	dfs(1, 0);

	for (int i = 2; i <= stamp; i++)
		log_2[i] = log_2[i / 2] + 1;

	for (int j = 1; j <= log_2[stamp]; j++)
		for (int i = 1; i + (1 << j) - 1 <= stamp; i++)
			a[i][j] = std::min(a[i][j - 1], a[i + (1 << (j - 1))][j - 1]);

	for (int i = 1; i <= n; i++) off[i] = true;

	std::cin >> m;
	for (int i = 0, x; i < m; i++) {
		char ch;
		std::cin >> ch;
		if (ch == 'G') {
			if (count <= 1) std::cout << count - 1 << '\n';
			else std::cout << ans.top() << '\n';
		} else {
			std::cin >> x;
			if (off[x]) { count--; turn_on(x); }
			else { count++; turn_off(x); }
			off[x] ^= true;
		}
	}
}

